<?php
namespace Nawa\MedicalStudy;
/**
 * Medical Study Followup Object.
 *
 * It represant the design of the MS, meaning while
 * the list of module that are activated in the MS
 *
 * @author Xavier VILAIN
 * @package Nawa\MedicalStudy
 *
 * @property string	$msid		MS id (12)
 * 
 * @method Nawa\MedicalStudy\Followp\ item()
 *
 */
class Followup extends \Fox\Object {

	/**
	 * 
	 * Reverse link to medical study
	 * @var string
	 */
	const LINK_MEDICAL_STUDY = 'medicalStudy';
	
	/**
	 * 
	 * Link to Follow up Object
	 * @var string
	 */
	const LINK_ITEMS = 'items';
	
	/**
	 * Item in the current language
	 * @var Followup\Item
	 */
	private $_item = null;
	
	/**
	 * Find Corresponding Item in current application language
	 * @return Followup\Item
	 */
	public function item() {
		if(empty($this->_item)) {
			try {
				$language = \Xview::instance()->language();
				$this->_item = \Fox\Dao::load(Followup\Item::className(),$this->followupid.':'.$language);
			} catch (\Fox\Object\Exception\NotExist $e) 
			{
				$this->_item = new Followup\Item();
			}
		}
		return $this->_item;
	}
	
	/**
	 * 
	 * Retrieve Followup Label
	 * Can be a code in case of multiple followup type or the 
	 * type label
	 * 
	 * @return string
	 */
	public function label() {
		$code = $this->code;
		if(!empty($code)) {
			return $code;
		} else {
			return $this->item()->label();
		}
	}
}
\Fox\Dao::infos(Followup::className(),new \Fox\Object\Info('ms_followup', \Fox\Databases::DB_APP))
->addAutoIncrementField('itemid');

// Link to Customer
\Fox\Object\Links::add(\Fox\Dao::link(Followup::className(), Followup::LINK_ITEMS)
->to(Followup\Item::className(),Followup\Item::LINK_MEDICAL_STUDY_FOLLOWUPS)
->on('followupid')
);